{extend name="layout:default" /}

{block name="title"}干部会员管理{/block}

{block name="content"}
<link href="https://cdn.bootcss.com/layer/2.2/skin/layer.css" rel="stylesheet">
<div class="row">

    <div class="col-xs-12">

        <div class="box">



            <div class="box-header">

                <h3 class="box-title">干部会员列表</h3>

                <div class="box-tools">

                    <a href="{:url('add')}" class="btn btn-info"> 添加 </a>
                </div>

            </div>
            <form class="form-inline clearfix" method="get">
               <div class="row pull-right" style="margin: 10px 10px 20px;">
                   <div class="form-group">
                       <input type="text" class="form-control" name="kw" value="{$Request.param.kw}" placeholder="请输入手机号\用户名\姓名">
                   </div>
                   <div class="form-group">
                       <label for="reservation">注册时间：</label>
                       <input type="text" name="start" class="form-control" value="{$Request.param.start}" id="reservation" placeholder="开始时间">
                   </div>
                   <div class="form-group">
                       <label for="reservation">至</label>
                       <input type="text" name="end" class="form-control" value="{$Request.param.end}" id="datepicker" placeholder="结束时间">
                   </div>
                   <div class="form-group">
                       <select name="is_cadre" class="form-control">
                           <option value="-1" {if $Request.param.is_cadre == -1} selected {/if}>不限</option>
                           <option value="0" {if $Request.param.is_cadre == 0} selected {/if}>已通过</option>
                           <option value="1" {if $Request.param.is_cadre == 1} selected {/if}>审核中</option>
                       </select>
                   </div>
                   <input type="submit" class="btn btn-primary" value="查询">
               </div>
            </form>
            <!-- /.box-header -->

            <div class="box-body table-responsive no-padding">

                <table class="table table-hover">
                    <tbody>
                    <tr>
                        <th>序号</th>
                        <th>姓名</th>
                        <th>手机号</th>
                        <th>是否审核</th>
                        <th>用户名</th>
                        <th>身份证号</th>
                        <th>是否禁用</th>
                        <th>注册时间</th>
                        <th>操作</th>
                    </tr>

                    {volist name="cadre" id="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.mobile}</td>
                        <td>{$vo.is_cadre === 1 ? '已通过' : '审核中'}
                        <td>{$vo.username}</td>
                        <td>{$vo.cardid}</td>
                        <td>{if $vo.is_cadre === 0}审核中{else}
                            <div class="switch" data-on-label="正常" data-off-label="禁用">
                                <input type="checkbox" onchange="status(this,{$vo.id})" {$vo.status == 1 ? 'checked': ''} /></div>
                            {/if}</td>
                        <td>{:date('Y-m-d H:i:s',$vo.cadre_addtime)}</td>
                        <td>
                            {if $vo.is_cadre === 0} <a href="javascript:;" class="pass btn btn-primary" data-id="{$vo.id}">审核</a>{/if}
                            <a title="修改" href="{:url('edit',['id'=>$vo.id])}" class="btn btn-success"><i
                                    class="glyphicon glyphicon-edit"></i></a>
                            {if $vo.is_cadre === 0} <a title="删除" href="{:url('del',['id'=>$vo.id])}" class="btn btn-danger"><i
                                class="glyphicon glyphicon-trash"></i></a> {/if}
                        </td>
                    </tr>
                    {/volist}
                    </tbody>

                </table>
                {$cadre->render()}
            </div>
            <!-- /.box-body -->
        </div>
        <!-- /.box -->
    </div>
</div>

<div class="modal fade" id="modal-pass">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">审核分班</h4>
            </div>
            <div class="modal-body">
                <form action="" method="post">
                    <div class="form-group">
                        <select name="class_id" id="class_id" class="form-control">
                        {volist name="cls" id="vo"}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="submit-save">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{/block}

{block name="js"}

<script src="https://cdn.bootcss.com/layer/2.2/layer.js"></script>
<script>
    // 审核
    $('.pass').click(function () {
        $('#modal-pass').modal();
        let id = $(this).data('id');
        $('#submit-save').click(function () {
            let classId= $('#class_id').val();
            $.post('/admin/cadre/pass', {'id':id, "class_id": classId}, function (data) {
                $('#modal-pass').modal('hide');
                if (data.code == 200) {let icon = 1}
                else  {icon = 2};
                layer.msg(data.message, {icon: icon});
            });

        });
    });
    function status(obj, id) {
        let s = +($(obj).prop("checked"));
        console.log(s, id);
        $.post('/admin/cadre/status', {id:id, status: s}, function (data) {
            if (data.status == 200) {
                layer.msg(data.message, {icon: 1})
            } else {
                layer.msg(data.message, {icon: 2})
            }
        });
    }
    $('#date').datepicker({
        autoclose: true,
        language: 'cn'
    });
    $('#reservation').datepicker({
        autoclose: true,
        language: 'cn'
    });
    $('#datepicker').datepicker({
        autoclose: true,
        language: 'cn'
    });

</script>
{/block}